package com.example.microinvestcommon.config;

import com.example.microinvestcommon.util.SnowflakeIdGeneratorUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SnowflakeConfig {

    @Value("${spring.snowflake.workerId}")
    private long workerId;

    @Value("${spring.snowflake.datacenterId}")
    private long datacenterId;

    // 定义 workerId 和 datacenterId 的 Bean
    @Bean
    public long workerId() {
        return workerId;
    }

    @Bean
    public long datacenterId() {
        return datacenterId;
    }

    // 定义 SnowflakeIdGeneratorUtil 的 Bean，注入 workerId 和 datacenterId
    @Bean
    public SnowflakeIdGeneratorUtil snowflakeIdGenerator(long workerId) {
        return new SnowflakeIdGeneratorUtil(workerId);
    }
}
